CentOS 7
Sponsored Link

PostgreSQL 9.2 : Install
2015/07/23
 
Install PostgreSQL to configure database server.
[1] Install and start PostgreSQL.
[root@dlp ~]#
yum -y install postgresql-server
[root@dlp ~]#
postgresql-setup initdb

Initializing database ... OK
[root@dlp ~]#
vi /var/lib/pgsql/data/postgresql.conf
# line 59: uncomment and change if allow accesses from remote hosts

listen_addresses = '
*
'
# line 395: uncomment and change if change log format

# the exmaple below is [Date User DB ***] format

log_line_prefix = '
%t %u %d
'
[root@dlp ~]#
systemctl start postgresql

[root@dlp ~]#
systemctl enable postgresql

[2] If Firewalld is running and also PostgreSQL is used from remote Hosts, allow service like follows.
[root@dlp ~]#
firewall-cmd --add-service=postgresql --permanent

success
[root@dlp ~]#
firewall-cmd --reload

success
[3] Set PostgreSQL admin user's password and add a user and also add a test database.
# set password

[root@dlp ~]#
su - postgres

-bash-4.2$
psql -c "alter user postgres with password 'password'"

ALTER ROLE
# add DB user "cent" as an example

-bash-4.2$
createuser cent
# create a test database (owner is the user above)

-bash-4.2$
createdb testdb -O cent
[4] Login as a user just added above and operate DataBase as test operation.
# show Databases

[cent@dlp ~]$
psql -l

                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileg
es
-----------+----------+----------+-------------+-------------+------------------
-----
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres    +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres    +
           |          |          |             |             | postgres=CTc/postgres
 testdb    | cent     | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
(4 rows)

# connect to test DB

[cent@dlp ~]$
psql testdb

psql (9.2.13)
Type "help" for help.
# set password

testdb=#
alter user cent with password 'password';

ALTER ROLE
# create a test table

testdb=#
create table test ( no int,name text );

CREATE TABLE
# insert test data

testdb=#
insert into test (no,name) values (1,'cent');

INSERT 0 1
# show tables

testdb=#
select * from test;
 no | name
----+-------
  1 | cent
(1 row)
# delete test table

testdb=#
drop table test;

DROP TABLE
# quit

testdb=#
\q
# delete test database

[cent@dlp ~]$
dropdb testdb
 
Tweet